<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="农忙互助订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="agriculturOrderCode">
              <a-input v-model="model.agriculturOrderCode" placeholder="请输入农忙互助订单编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所需人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="needPeople">
              <a-input-number v-model="model.needPeople" placeholder="请输入所需人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="已报名人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicant">
              <a-input v-model="model.applicant" placeholder="请输入已报名人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workspace">
              <a-input v-model="model.workspace" placeholder="请输入工作地点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title">
              <a-input v-model="model.title" placeholder="请输入标题"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobType">
              <a-input v-model="model.jobType" placeholder="请输入工种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否提供接送(0提供、1不提供)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPickup">
              <a-input-number v-model="model.isPickup" placeholder="请输入是否提供接送(0提供、1不提供)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年龄限制" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ageLimit">
              <a-input v-model="model.ageLimit" placeholder="请输入年龄限制"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settlementModes">
              <a-input v-model="model.settlementModes" placeholder="请输入结算方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input v-model="model.price" placeholder="请输入价格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名状态(0已报名、1未报名)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicantStatus">
              <a-input-number v-model="model.applicantStatus" placeholder="请输入报名状态(0已报名、1未报名)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态（0已完成、1未完成）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <a-input-number v-model="model.orderStatus" placeholder="请输入订单状态（0已完成、1未完成）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userid">
              <a-input v-model="model.userid" placeholder="请输入用户id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作详情" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobDetails">
              <a-input v-model="model.jobDetails" placeholder="请输入工作详情"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'AgriculturalAssistanceWorkForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           agriculturOrderCode: [
              { required: true, message: '请输入农忙互助订单编号!'},
           ],
        },
        url: {
          add: "/agricultural/assistanceWork/add",
          edit: "/agricultural/assistanceWork/edit",
          queryById: "/agricultural/assistanceWork/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>